﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VocabLib;

namespace VocabGUI
{
	public class ViewModel : INotifyPropertyChanged
    {
		public class Answer : INotifyPropertyChanged
        {
            public string Hun { get; set; }
            public string EngAnswer { get; set; }
            public string EngCorrect { get; set; }
            public string EngAnswerAndCorrect
            {
                get
                {
                    return IsCorrect ? EngAnswer : EngAnswer + " (" + EngCorrect + ")";
                }
            }
			public bool IsCorrect { get; set; }
			public bool ValidPage { get; set; }
			public event PropertyChangedEventHandler PropertyChanged;

			protected virtual void OnPropertyChanged(string propertyName)
			{
				PropertyChangedEventHandler handler = PropertyChanged;
				if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
			}
        }

        public int TotalWordPairCount { get; set; }
        public int CorrectAnswerCount { get; set; }
        public int WrongAnswerCount { get; set; }
        public double PositiveCoveragePercent { get; set; }
        public string FormattedPositiveCoveragePercent
        {
            get
            {
                return string.Format("{0:0.##} %", PositiveCoveragePercent);
            }
        }
		public int LearnedWordCount { get; set; }
		public int NotKnownWordCount { get; set; }
		public ObservableCollection<Answer> Answers { get; set; }

        public ViewModel()
        {
            TotalWordPairCount = 0;
            CorrectAnswerCount = 0;
            WrongAnswerCount = 0;
			Answers = new ObservableCollection<Answer>();
        }

		public void AddAnswer( string answerText, VocabLib.VocabModel.Record question, bool isCorrect, bool validPage )
        {
            Answer newAnswer = new Answer
	                               {
		                               IsCorrect = isCorrect,
									   ValidPage = validPage,
		                               Hun = question.Hun,
		                               EngCorrect = question.Eng,
		                               EngAnswer = answerText
	                               };

	        Answers.Insert(0, newAnswer);
            if (isCorrect)
                CorrectAnswerCount++;
            else
                WrongAnswerCount++;
        }

		public event PropertyChangedEventHandler PropertyChanged;

		protected virtual void OnPropertyChanged(string propertyName)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
		}
    }
}
